using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

public class BtnEventListener : MonoBehaviour
{
    public  Text text;
    // Start is called before the first frame update
    void Start()
    {
        GetComponent<Button>().onClick.AddListener(ChangeText);  //监听事件
        // GetComponent<Button>().onClick.AddListener(() =>     //调用协程参数两种方式
        // {
        //     text.text = "111111111111";
        // });  
    }

    private void OnDestroy()
    {
        GetComponent<Button>().onClick.RemoveListener(ChangeText);
    }

    private void OnEnable()
    {
        GetComponent<Button>().onClick.RemoveListener(ChangeText);
    }


    public void ChangeText()
    {
        Debug.Log("accept event ...");
        text.text = "123456789";
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
